package com.im.servlets;

import java.io.IOException;
import java.io.PrintWriter;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import com.im.dao.MemberDAO;
import com.im.entity.Member;


@WebServlet("/login")
public class LoginServlet extends HttpServlet {
	private static final long serialVersionUID = 1L;

	
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		String email = request.getParameter("email");
		String password = request.getParameter("password");
		Member member = MemberDAO.login(email, password);
		if(member != null){
			
			//Handle Session
			HttpSession session = request.getSession();
			session.setAttribute("name", member.getName());
			
			response.sendRedirect("member/car_list.jsp");
		}else{
			PrintWriter out = response.getWriter();
			out.print("<h1>Incorrect Login!</h1>");
		}
	}

}
